package videoExercises;

import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Test11Stream {
    public static void main(String[] args) {
        //单列集合
        ArrayList<String> list =new ArrayList<>();
        list.add("天天");
        list.add("睡觉");
        list.add("吃");
        list.add("美食");
        Stream<String> stream = list.stream();
        stream.forEach(n->{
            System.out.println(n);
        });

       //另一种更简洁的方式 list.stream().forEach(n->System.out.println(n));
        //双列集合  注意不能直接使用stream流，需要先将双列集合转换成单列集合
        HashMap<String , Integer> hash =new HashMap<>();
        hash.put("小布丁",1);
        hash.put("钟薛高",100);
        hash.put("好心情",3);
        hash.put("老冰棍",2);
        hash.put("阿根达斯",50);
        //双列集合的第一种获得stream流方式
        Set<String> strings = hash.keySet();
        Stream<String> stream1 = strings.stream();
        stream1.forEach(n->System.out.println(n));
        //双列集合的第二种获得stream流方式
        Set<Map.Entry<String, Integer>> entries = hash.entrySet();
        Stream<Map.Entry<String, Integer>> stream2 = entries.stream();
        stream2.forEach(s->System.out.println(s));

        //数组的stream流
        int[] arr ={1,2,3,4,5,6,7,8,9};
        String[] arr1 ={"我","是","小","布","丁"};
        IntStream stream3 = Arrays.stream(arr);
        stream3.forEach(n->System.out.println(n));
        Stream<String> stream5 = Arrays.stream(arr1);
        stream5.forEach(n->System.out.println(n));
        //可变参数
        Stream<Integer> stream4 = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
        Stream<String> stream6 = Stream.of("我", "是", "小", "布", "丁");
        stream4.forEach(n->System.out.println(n));
        stream6.forEach(n->System.out.println(n));
    }
}
